<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Dark Mode Demo</title>
    <style>
        :root {
            --bg-color: #ffffff;
            --text-color: #333333;
            --btn-bg: #f0f0f0;
            --btn-text: #333333;
        }

        html.dark {
            --bg-color: #121212;
            --text-color: #e0e0e0;
            --btn-bg: #333333;
            --btn-text: #e0e0e0;
        }

        body {
            background-color: var(--bg-color);
            color: var(--text-color);
            font-family: Arial, sans-serif;
            transition: background-color 0.3s, color 0.3s;
            margin: 0;
            padding: 20px;
            box-sizing: border-box;
        }

        .container {
            max-width: 800px;
            margin: 0 auto;
        }

        h1 {
            text-align: center;
        }

        p {
            line-height: 1.6;
        }

        button {
            background-color: var(--btn-bg);
            color: var(--btn-text);
            border: none;
            padding: 10px 20px;
            border-radius: 5px;
            cursor: pointer;
            font-size: 16px;
            transition: background-color 0.3s, color 0.3s;
            display: block;
            margin: 20px auto;
        }

        button:hover {
            opacity: 0.8;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>Dark Mode Example</h1>
        <p>This is a simple demonstration of dark mode toggle.</p>
        <p>Click the button below to switch between light and dark modes.</p>
        <button id="toggleBtn">Toggle Dark Mode</button>
    </div>

    <script>
        const toggleBtn = document.getElementById('toggleBtn');
        const html = document.documentElement;

        // 检查本地存储，恢复上次的模式
        if (localStorage.getItem('darkMode') === 'true') {
            html.classList.add('dark');
            toggleBtn.textContent = 'Switch to Light Mode';
        }

        toggleBtn.addEventListener('click', () => {
            const isDark = html.classList.toggle('dark');
            localStorage.setItem('darkMode', isDark);
            toggleBtn.textContent = isDark ? 'Switch to Light Mode' : 'Switch to Dark Mode';
        });
    </script>
</body>
</html>